package com.JFapp.service.impl;

import com.JFapp.constants.SystemConstants;
import com.JFapp.eumns.AppHttpCodeEnum;
import com.JFapp.service.MailService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;


@Service("mailService")
public class MailServiceImpl implements MailService {
    @Autowired
    private JavaMailSender mailSender;
    @Override
    public void sendEmail(String subject, String body, String email) {
        try {
            SimpleMailMessage message= new SimpleMailMessage();
            message.setSubject(subject);
            message.setText(body);
            message.setTo(email);
            message.setFrom(SystemConstants.SEND_EMAIL);
            mailSender.send(message);
        } catch (MailException e) {
            throw new RuntimeException(AppHttpCodeEnum.SEND_EMAIL_FAIL.getMessage());
        }
    }
}
